//防抖函数
export function debounce(func, delay) {
	let timer
	return function(...args) {
		if(timer) clearTimeout(timer)
		timer = setTimeout(() => {
			func.apply(this, args)
		}, delay)
	}
}
//节流函数
export function throttling(func, delay) {
	let canRun = true
	return function(...args) {
		if(!canRun) return
		canRun = false
		setTimeout(() => {
			func.apply(this, args)
			canRun = true
		}, delay)
	}
} 
//对象浅拷贝
export function shallowCopy(src) {
	let copy = {}
	for(i in src) {
		if(src.hasOwnProperty(i)) {
			copy[i] = src[i]
		}
	}
	return copy
}
//深拷贝
export function deepCopy(src) {
	let copy = typeof src.splice === "function" ? [] : {}
	if(src === null) return src
	if(src instanceof Date) return new Date(src)
	if(src instanceof RegExp) return new Date(src)
	if(typeof src !== "object") return src
	for(i in src) {
		if(src.hasOwnProperty(i)) {
			copy[i] = deepCopy(src[i])
		}
	}
	return copy
}